let dfdDB = require("../db/dfdDB.js");
let findImage = require("../module/IMG/findImage.js");

var dfdObj = (function () {
  // 全局配置
  let obj = {
    faceValue: 80, // 颜值
    starNum: 10, // 数量
    gender: "female", // 性别
    appPackage: "com.ss.android.ugc.aweme", // 抖音包名
    ak: "KXIS86UejDFk9RzMxYp0DFMF", // 百度云图像识别ak
    sk: "C93QyBiG346cTezoECXQsGcUsszaln4G", // 百度云图像识别sk
    favoriteBase64: "", // 点赞 图片的Base64码
    focusOnBase64: "", // 关注 图片的Base64码
    updatePath: "./", // //更新路径
    videoAllTime: 30, // 单个视频最长识别时间(s)
    eggA: 1, // 神秘正向彩蛋！
    eggB: 1, // 神秘负向彩蛋！
  };

  // 全局变量
  let obc = {
    favorLocation: dfdDB.getValueByParam("favorLocation") == null ? "" : dfdDB.getValueByParam("favorLocation"), // 点赞控件的中心
    focusOnLocation: dfdDB.getValueByParam("focusOnLocation") == null ? "" : dfdDB.getValueByParam("focusOnLocation"), // 关注控件的中心
  };

  let q = {};

  /**
   * 设置全局配置
   * @param {*} param
   * @param {*} value
   */
  q.setDfdObjParam = function (param, value) {
    dfdDB.setValueByParam(param, value);
  };

  /**
   * 获取全局配置
   * @param {*} param
   * @returns
   */
  q.getDfdObjParam = function (param) {
    if (dfdDB.getValueByParam(param) == null) {
      if (param == "favorLocation") {
        if (obc[param] == "") {
          obc[param] = findImage.getImageLocation(obj["favoriteBase64"], 0.9, [
            device.width / 2,
            device.height / 4,
          ]); // 找图区域，目前设置为设备右半边的下3/4
        }
        if (obc[param] != "") dfdDB.setValueByParam(param, obc[param]);
      } else if (param == "focusOnLocation") {
        if (obc[param] == "") {
          obc[param] = findImage.getImageLocation(obj["focusOnBase64"], 0.9, [
            device.width / 2,
            device.height / 4,
          ]); // 找图区域，目前设置为设备右半边的下3/4
        }
        if (obc[param] != "") dfdDB.setValueByParam(param, obc[param]);
      } else {
        log("插入值【" + param + "】:[" + obj[param] + "]");
        dfdDB.setValueByParam(param, obj[param]);
        log("检查插入值【" + dfdDB.getValueByParam(param) + "】");
      }
    }
    return dfdDB.getValueByParam(param);
  };
  return q;
})();
module.exports = dfdObj;